# Run preamble
source("code/preamble.R")

# Load data
study3_data <- readRDS("data/study3_data.rds")
study4_data <- readRDS("data/study4_data.rds")
study5_data <- readRDS("data/study5_data.rds")

# Subset Study 3 data
study3_data <- study3_data %>%
    subset(condition == "dist_no_correct") # Dropping treated participants from unrelated experiment

# Subset Study 5 data
study5_data <- study5_data %>%
    subset(condition == "dist_no_correct") # Dropping treated participants from unrelated experiment

# Subset and clean Study 4 data
study4_data <- study4_data %>%
    subset( # Drop Independents and participants in the placebo conditions
        !is.na(pid2) & condition != "Blue vs. Pink" &
            condition != "Red Sox vs. Yankees"
    ) %>%
    mutate( # Create policy column
        policy = condition %>%
            as.character() %>%
            factor(
                levels = c(
                    "Gun Control",
                    "Border Control",
                    "Abortion Access"
                )
            )
    )

########################
### CALCULATE ALPHAS ###
########################

# Study 3
## Comfort Socializing with Out-Party
cat(
    "\n\n",
    " Cronbach's alpha for comfort socializing with out-party (Study 3):",
    "\n"
)

study3_data %>%
    select(outparty_friend, outparty_neighbor, outparty_marriage) %>%
    alpha() %>%
    use_series("total") %>%
    use_series("std.alpha") %>%
    print()

## Perception that Out-Party Supports Violating Democratic Norms
cat(
    "\n\n",
    " Cronbach's alpha for perceived out-party support for violating democratic norms (Study 3):",
    "\n"
)

study3_data %>%
    select(outparty_judges, outparty_voting, outparty_violence) %>%
    alpha() %>%
    use_series("total") %>%
    use_series("std.alpha") %>%
    print()

# Study 4
## Comfort Socializing with Out-Party
cat(
    "\n\n",
    " Cronbach's alpha for comfort socializing with out-party (Study 4):",
    "\n"
)

study4_data %>%
    select(outparty_friend, outparty_neighbor, outparty_marriage) %>%
    alpha() %>%
    use_series("total") %>%
    use_series("std.alpha") %>%
    print()

## Perception that Out-Party Supports Violating Democratic Norms
cat(
    "\n\n",
    " Cronbach's alpha for perceived out-party support for violating democratic norms (Study 4):",
    "\n"
)

study4_data %>%
    select(outparty_judges, outparty_voting, outparty_violence) %>%
    alpha() %>%
    use_series("total") %>%
    use_series("std.alpha") %>%
    print()

# Study 5
## Perception that Out-Party Supports Violating Democratic Norms
cat(
    "\n\n",
    " Cronbach's alpha for perceived out-party support for violating democratic norms (Study 5):",
    "\n"
)

study5_data %>%
    select(outparty_judges, outparty_voting, outparty_violence) %>%
    alpha() %>%
    use_series("total") %>%
    use_series("std.alpha") %>%
    print()
